<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<s:action name="header" executeResult="true">
	<s:param name="titles">Giỏ hàng</s:param>
</s:action>
<s:action name="sidebar" executeResult="true" />

<!-- Center -->
<div id="center_column_des" class="center_column">

<!-- MODULE check out -->
<!-- Breadcrumb -->
<div class="breadcrumb">
	<a href="<s:url action="index"></s:url>" title="Quay trở lại trang chủ">Trang chủ</a><span class="navigation-pipe">&gt;</span><span class="navigation_page">Giỏ hàng</span>
</div>
<!-- /Breadcrumb -->
	<s:if test="%{perror != null}" >
	<div class="error" style="text-align:center;color: #CC0000;"><s:property value="perror" /></div>
	</s:if>
	<div id="order-detail-content" class="table_block">
		<s:set name="cart" value="cart"/>
		<s:if test="%{#cart.size > 0}" >
		<table id="cart_summary" class="std">
			<thead>
				<tr>
					<th class="cart_product first_item">Sản phẩm</th>
					<th class="cart_description item" colspan="3">Mô tả</th>
					<th class="cart_unit item">Đơn giá</th>
					<th class="cart_quantity item">Số lượng</th>
					<th class="cart_total last_item">Tổng cộng</th>
				</tr>
			</thead>
			<tfoot>
				<tr class="cart_total_price">
					<td colspan="6">Tổng tiền :</td>
					<td class="price" id="total_price"><span class="price"><s:property value="totalPrice" /> VNĐ</span>
					</td>
				</tr>
			</tfoot>
			<tbody>
				<s:set name="products" value="products"/>
				<s:iterator value="#cart" var="c">
				<tr class="cart_item">
					<td class="cart_product">
						<a href="<s:url action="detail"><s:param name="pid" value="#products[#c.key].product_id" /></s:url>"><img src="<s:property value="#products[#c.key].image_main" />" width="45"></a>
					</td>
					<td class="cart_description" colspan="3">
						<h5>
							<a class="product_link" href="<s:url action="detail"><s:param name="pid" value="#products[#c.key].product_id" /></s:url>"><s:property value="#products[#c.key].title" /></a>
						</h5>
					</td>
					<td class="cart_unit">
						<span class="price" id="product_price_1_0"> <s:property value="#products[#c.key].price" /> VNĐ </span>
					</td>
					<td class="cart_quantity">
						<div id="cart_quantity_button">
							<input onkeypress="return isNumberKey(event)" class="cart_quantity_input text" size="2" type="text" maxlength="3" value="<s:property value="#c.value" />" id="qty<s:property value="#products[#c.key].product_id" />" name="qty<s:property value="#products[#c.key].product_id" />"> 
						</div> 						
						<a class="cart_quantity_delete" rel="nofollow" href="javascript;;">
							<img src="images/save.png" alt="Lưu" title="Lưu" class="icon" height="11" width="11" onclick="editor(<s:property value="#products[#c.key].product_id" />,'change');return false;">
							<img src="images/delete.gif" alt="Xóa" title="Xóa" class="icon" style="margin-top:2px;" onclick="if(confirm('Bạn có muốn xóa sản phẩm này ra khỏi giỏ hàng không?')){editor(<s:property value="#products[#c.key].product_id" />,'del');}return false;">
						</a> 
					</td>
					<td class="cart_total">
						<span class="price" id="total<s:property value="#products[#c.key].product_id" />" > <s:property value="#products[#c.key].price * #c.value" /> VNĐ</span>
					</td>
				</tr>
				</s:iterator>
			</tbody>
		</table>		
		</s:if>
		<s:else>
			<h3 align="center">Không có sản phẩm nào trong giỏ hàng !</h3>
		</s:else>
	</div>

	<p class="cart_navigation">
		<a href="<s:url action="payment"></s:url>" class="exclusive" title="Đặt hàng">Đặt hàng »</a>	<a href="<s:url action="index"></s:url>" class="button_large" title="Tiếp tục mua hàng">« Tiếp tục mua hàng</a>
	</p>

<!-- /MODULE check out -->	
	<form action="<s:url action="checkout"></s:url>" method="post" class="std" enctype="multipart/form-data" id="editor">
		<input type="hidden" value="" name="pid" id="pid" />
		<input type="hidden" value="" name="pqty" id="pqty"/>
		<input type="hidden" value="" name="paction" id="paction" />
	</form>
<script type="text/javascript">
function editor(productId,action){
	var pidVal = $("#pid");
	var pqtyVal = $("#pqty");
	var pactionVal = $("#paction");
	var editorVal = $("#editor");
	var qtyVal = $("#qty"+productId).val();
	pidVal.val(productId);
	if(action == "del"){
		pactionVal.val("del");
	}else{
		pactionVal.val("change");
		if(qtyVal < 1){
			alert("Số lượng sản phẩm phải lớn 0");
			return false;
		}
	}
	pqtyVal.val(qtyVal);
	editorVal.submit();
}

function isNumberKey(evt)
{
   var charCode = (evt.which) ? evt.which : event.keyCode
   if (charCode > 31 && (charCode < 48 || charCode > 57))
      return false;

   return true;
}
</script>	
	
</div>

<s:action name="footer" executeResult="true" />